<template>

  <section class="index-recommend">
    <div class="recommend">
      <div class="recommend_title">
        <div class="line"></div>
        <div class="texts">为您推荐</div>
        <div class="line"></div>          
      </div>
      <div class="recommend_main" v-for="(item,index) in recommendArr" :key="index">
        <div class="imgs">
          <router-link :to="{path:'/ProductDetails',query: {id: item.gid}}"><img :src="item.image" alt=""></router-link>
        </div>
        <p class="p1">{{ item.title }}</p>
        <p class="p2">{{ item.price }}</p>
      </div>
    </div>
  </section>

</template>

<script>
// 引入接口
import { indexRecommend } from "../api/api";

import axios from 'axios';
  export default  {
    name: 'index-recommend',
    props: [],
    created() {
        // 获取推荐数据
        this.getRecommend();
    },
    data() {
      return {
        recommendArr:[],
      }
    },
    methods: {
      // 获取推荐数据
      getRecommend(){
        var token = '1ec949a15fb709370f';
        
        indexRecommend(token).then(res=>{
          // console.log(999, res);
          this.recommendArr = res.data.data;
        });
      }
    },
    computed: {

    }
}
</script>

<style scoped>
  .recommend_title{
    height: 1.03rem;
    clear: both;
    display: flex;
    -webkit-box-flex: 1;
    -webkit-box-align: center;
    justify-content: space-between;
    font-size: 0.31rem;
  }
  .recommend_title .line{
    width: 35%;
    height: 1px;
    background-color: #D4D4D4;
    margin-top: 6%;
  }
  .recommend_title .texts{
    width: 28%;
    height: 1.1rem;
    text-align: center;
    margin-top: 3.5%;
    background-image: url("../assets/main_img/heart.png");
    background-size: 0.4rem;
    background-repeat: no-repeat;
    background-position: 0.2rem top;
    padding-left: 0.3rem;
    overflow: hidden;
  }
  .recommend_main{
    width: 48%;
    height: 3.76rem;
    float: left;
    background: #fff;
    margin: 0 0.05rem 0 0.07rem;
    margin-bottom: 0.22rem;
  }
  .recommend_main .imgs{
    text-align: center;
  }
  .recommend_main img{
    width: 2.4rem;
    height: 2.4rem;
  }
  .recommend_main .p1{
    width: 97%;
    height: 0.5rem;
    line-height: 0.25rem;
    text-overflow: ellipsis;
    margin-top: 0.1rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    margin-left: 0.06rem;
    
  }
  .recommend_main .p2{
    color: #d32a4e;
    margin-left: 0.06rem;
  }
</style>
